package com.tjnu.losca.service.impl;

import com.tjnu.losca.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author Losca
 * @date 2021/9/16 19:29
 */
@Service
public class MailServiceImpl implements MailService {
    @Autowired
    //JavaMailSender是spring-boot-starter-mail自带的，发消息用
    JavaMailSender sender;

    @Value("${spring.mail.username}")
    private String from;

    @Async
    @Override
    public void asyncService(String to) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject("系统消息");
        message.setText("您已经被添加到教务系统");
        sender.send(message);
    }
}
